package org.example.controller;

import org.example.model.common.dtos.ResponseResult;
import org.example.model.common.vos.order.SearchOrderVo;
import org.example.model.order.OrderBasic;
import org.example.service.OrderBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理
 */
@CrossOrigin
@RestController
@RequestMapping("/order-basic")
public class OrderBasicController {

    @Autowired
    private OrderBasicService orderBasicService;

    /**
     * 添加订单
     */
    @PostMapping("/order-basic")
    public ResponseResult InsertOrderBasic(@RequestBody OrderBasic orderBasic) {
        return ResponseResult.okResult(orderBasicService.InsertOrderBasic(orderBasic));
    }

    /**
     * 根据条件(订单号模糊查询，订单状态精确查询,下单时间范围查询)分页查询
     */
    @GetMapping("/order-list/{pageIndex}/{pageSize}")
    public ResponseResult SelectOrderPageByConditions(SearchOrderVo searchOrderVo,@PathVariable int pageIndex,@PathVariable int pageSize) {
        return ResponseResult.okResult(orderBasicService.SelectOrderPageByConditions(searchOrderVo, pageIndex, pageSize));
    }

    /**
     * 根据id修改订单状态
     */
    @PutMapping("/order-basic")
    public ResponseResult UpdateOrderBasicById(@RequestBody OrderBasic orderBasic) {
        return ResponseResult.okResult(orderBasicService.UpdateOrderBasicById(orderBasic));
    }

    /**
     * 根据id查询详情
     */
    @GetMapping("/order-basic/{id}")
    public ResponseResult SelectOrderById(@PathVariable int id) {
        return ResponseResult.okResult(orderBasicService.SelectOrderById(id));
    }
}
